package com.huang.consumer_mall.util;


import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class EmailUtils {
    public static void send_mail(String to, String text) throws  MessagingException {
        Properties properties = new Properties();
        properties.put("mail.transport.protocol", "smtp"); //连接协议
        properties.put("mail.smtp.host", "smtp.qq.com");// 主机名
        properties.put("mail.smtp.port", 465);// 端口号
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.ssl.enable", "true");// 设置是否使用ssl安全连接 ---一般都使用

        Authenticator auth = new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("1330406783@qq.com", "ptrhimudextcfeba");
            }
        };
        Session session = Session.getInstance(properties, auth);
        Message message =new MimeMessage(session);
        message.setFrom(new InternetAddress("1330406783@qq.com"));
        message.setRecipient(Message.RecipientType.TO,new InternetAddress(to));
        message.setSubject("本次你的验证码,请在五分钟内使用！");
        message.setContent(text,"text/html;charset=UTF-8");
        Transport.send(message);
    }
}
